package com.itheima.reggie.service.impl;

import com.itheima.reggie.service.SendMailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

@Service
public class SendMailServiceImpl implements SendMailService {

    @Autowired
    private JavaMailSender javaMailSender;

     //发送人
    private String from = "2268548539@qq.com";
     //接收人
    private String to = "2375170096@qq.com";
     //标题
    private String subject = "瑞吉外卖登录验证码";
     //正文
    private String context = "测试邮件正文";

    private String prefix = "您收到的注册验证码为：";

    private String suffix = " ,请勿泄露，五分钟内有效。[该邮件为测试邮件请勿回复]";

    @Override
    public void sendMail(String code,String mail) {
        this.context = code;
        this.to = mail;
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(from + "(管理员)");
        message.setTo(to);
        message.setSubject(subject);
        message.setText(prefix + context + suffix);
        javaMailSender.send(message);
    }
}
